package com.sumer.psychology.sharing.infrastructure.persistence.mongo;

import com.mongodb.DBObject;
import com.sumer.psychology.common.persistence.mongodb.AbstractSimpleMongoRepository;

/**
 * mongo资源分享资源库
 * <p/>
 * User: zhenguang.zhu
 * Date: 2014/11/3
 * Time: 14:17
 */
public class MongoSharedResourceRepository extends AbstractSimpleMongoRepository {
    private static final String DB_NAME = "sumer_resource";
    private static final String KEY = "sharedResourceId.identity";

    @Override
    protected String key() {
        return KEY;
    }

    @Override
    protected String dbName() {
        return DB_NAME;
    }

    @Override
    public void add(String data) {
        DBObject dbObject = initializeCreateData(data, key());
        dbObject.put("views", 0);
        dbObject.put("replies", 0);
        dbObject.put("downloads", 0);
        db().getCollection(dbName()).insert(dbObject);
    }
}
